﻿//打印控件调用
var LODOP; //声明为全局变量
var p_id="";
var header = $("meta[name='_csrf_header']").attr("content");
var token = $("meta[name='_csrf']").attr("content");
var printNum=0;
var printTime=0;
var printCurrent=0;
var pstate="true";
//返回
function fanhui(){
    $("#certNumber").val("");
    $("#name").html("");
    $("#sex").html("");
    $("#nation_").html("");
    $("#birthday").html("");
    $("#address").html("");
    $("#idcard").html("");
    $("#banum").val("");
    $("#phone").val("");
    $("#header_name_pay").html("");
    $("#validation").val("");
    $("#choice").val("");
    $("#crdiv").attr("class","modal_ modal_stamp");
    $("#sfzdiv").attr("class","modal_1 modal  hide");
    $("#div_key").attr("class","modal_key modal hide");
    $("#dy_validation").attr("");
}

//刻录光盘复制图片
function copyBanum(){
    var orgcode=$("#orgcode").val();
    var idcard=$("#idcard_").val();
    var basepath=$("#basepath").val();
    var obj=$("[name='dvd_checkbox'][checked]");
    check_val = [];
    var onlyIds='';
    for(k in obj){
        if(obj[k].checked){
            check_val.push(obj[k].value);
            onlyIds+=","+obj[k].value;
        }
    }
    //没选择弹窗提示
    if(check_val.length==0){
        $(document.body).append("<div class='alert fade in alert_warn'><button type='button' id='btn_warn' onclick='close_warn()' class='close'>&times;</button><div class='warn_div'><font class='font9' id='warn'>请选择病案后刻录!</font></div>	<div class='warn_div_'><font class='font5' id='warn_'>5</font></div></div>");
        settime_warn($("#btn_warn"));
        return false;
    }
    //alert(check_val);
    var path="f:/test";
    //progress_dvd(1);
    $.ajax({
        cache: true,
        type:"POST",
        url:basepath+"/spmr/copyBanumByOnlyId",
        dataType:"json",
        data:{onlyIds:onlyIds,orgcode:orgcode,filePath:path},
        async: true,
        beforeSend: function(xhr){
            xhr.setRequestHeader(header, token);
        },
        success:function(data){
            if (typeof (data) == "string"){
                var param=data;
                if(param=='success'){
                    //alert("复制完成");
                }else{
                    $("#bar_dvd_close").remove();
                    $(document.body).append("<div class='alert fade in alert_warn'><button type='button' id='btn_warn' onclick='close_warn()' class='close'>&times;</button><div class='warn_div'><font class='font9' id='warn'>请重新读取身份证或到人工窗口办理!</font></div>	<div class='warn_div_'><font class='font5' id='warn_'>5</font></div></div>");
                    settime_warn($("#btn_warn"));
                }

            }

        },
        error:function(){
            $("#bar_dvd_close").remove();
            $(document.body).append("<div class='alert fade in alert_warn'><button type='button' id='btn_warn' onclick='close_warn()' class='close'>&times;</button><div class='warn_div'><font class='font9' id='warn'>请重新读取身份证或到人工窗口办理!</font></div>	<div class='warn_div_'><font class='font5' id='warn_'>5</font></div></div>");
            settime_warn($("#btn_warn"));

        }
    });
}



function myPrint() {
    var orgcode=$("#orgcode").val();
    var onlyId=$("[name='banum_checkbox'][checked]").val();
    var combinationContent=$("[name='combination_checkbox'][checked]").val();
    var combinationId=$("[name='combination_checkbox'][checked]").attr("combinationId");
    var fs=$("#input_fs").val();
    var basepath=$("#basepath").val();
    if(onlyId==undefined){
        //$("#myModal").append("<div class='alert fade in alert_warn_'><div class='warn_div'><font class='font9' id='warn'>请选择病案!</font></div>	<div class='warn_div_'><font class='font5' id='warn_'>5</font></div></div>");
        $(".btn_fs").attr("disabled",true);
        $("#myModal").append("<div class='alert_warn_banum modal'  onclick='closeBanum()'><div class='warn_div_banum'><font class='font12' id='warn'>请选择病案!</font></div></div>");
        //$(".btn_fs").attr("disabled",true);
        settime_banum($(".alert_warn_banum"),5);
        //settime_warn($("#btn_warn"));
    }else if(combinationContent==undefined){
        $("#myModal").append("<div class='alert fade in alert_warn_'><button type='button' id='btn_warn' onclick='close_warn()' class='modal_close'>&times;</button><div class='warn_div'><font class='font9' id='warn'>请选择病案用途!</font></div>	<div class='warn_div_'><font class='font5' id='warn_'>5</font></div></div>");
        $(".btn_fs").attr("disabled",true);
        settime_warn($("#btn_warn"));
    }else{
        $(".btn_fs").attr("disabled",true);
        var	speed=1;

        var check=$('input[id^=banum_checkbox_]:checked');
        //意思是选择被选中的checkbox
        //打开串口及签章机
        var flag= OpenCom("2");
        if(flag==0){
            RunStamp(2);
        }
        if(check.length>1){
            choice_print(combinationContent,orgcode);
        }else{
            $("#onlyId").val(onlyId);
            $.ajax({
                cache: true,
                type:"POST",
                url:basepath+"/spmr/findImg",
                dataType:"json",
                data:{
                    onlyId:onlyId,
                    combinationContent:combinationContent,
                    orgcode:orgcode,
                    fs:fs,
                    combinationId:combinationId,
                    paymentVoucher:	$("#paymentVoucher").val()
                },
                async: true,
                beforeSend: function(xhr){
                    xhr.setRequestHeader(header, token);
                },
                success:function(data){

                    var num=data.length;
                    //printCurrent+=num;
                    if(data.length>0){
                        $(".alert_warn_").remove();
                        //$("#myModal").append("<div class='alert fade in alert_warn_' id='dy_alert'><div class='warn_div'><font class='font9' id='warn'>请稍后，正在调取病案...</div></div>");
                        $("#myModal").append("<div class='alert_warn_new modal' id='dy_alert'><div class='warn_div_dq'><font class='font12' id='warn'>请稍后，正在调取病案...</font></div></div>");

                        $("#dy_alert").append("<div class='alert fade in bar_warn warn_dq' id='bar_close'><div  class='progress progress-striped active'><div class='bar' id='bar_dy' style='width: 1%;'></div></div></div>");
                        //settime_progress($("#dy_alert"),num*0.3+2);
                        progress_bar_dq(10,2);
                        //进度条开启
                        //progress_bar(speed);
                        My_Print(data);
                        getDyStateNum(num,fs,data,fs);
                    }else{

                        $("#myModal").append("<div class='alert fade in alert_warn_'><button type='button' id='btn_warn' onclick='close_warn()' class='modal_close'>&times;</button><div class='warn_div'><font class='font9' id='warn'>病案暂未扫描，请咨询人工窗口！</font></div>	<div class='warn_div_'><font class='font5' id='warn_'>20</font></div></div>");
                        $(".btn_fs").attr("disabled",true);
                        settime_down($("#btn_warn"),20);
                        setTimeout("window.location.reload()",20000);
                    }
                    // setTimeout("close_war()",8000+1000*num*fs);
                },
                error:function(){
                    $("#myModal").append("<div class='alert fade in alert_warn'><button type='button' id='btn_warn' onclick='close_warn()' class='modal_close'>&times;</button><div class='warn_div'><font class='font9' id='warn'>请重新读取身份证或到人工窗口办理!</font></div>	<div class='warn_div_'><font class='font5' id='warn_'>5</font></div></div>");
                    settime_warn($("#btn_warn"));
                }
            });

        }
    }

};

function choice_print(combinationContent,orgcode){
    var check_id;
    var onlyId;
    var check=$('input[id^=banum_checkbox_]:checked');
    var combinationId=$("[name='combination_checkbox'][checked]").attr("combinationId");
    var basepath=$("#basepath").val();
    var fs=$("#input_fs").val();
    var speed=0.5;
    if(check.length>0){
        $.each(check,function(){
            onlyId=$(this).val();
            $("#onlyId").val(onlyId);
            check_id=$(this).attr("id");
            var trid_=check_id.split("_")[1]+"_"+check_id.split("_")[0]+"_"+check_id.split("_")[2];
            $("#"+trid_).removeAttr("onclick");
        });
        if(check_id){
            var trid=check_id.split("_")[1]+"_"+check_id.split("_")[0]+"_"+check_id.split("_")[2];
            $("#"+trid).attr("style","background:rgba(199, 221, 239, 1)");
            var tdid_=check_id.split("_")[0]+"_td_"+check_id.split("_")[2];
            $("#"+tdid_).html("<font style='font-size:16px;color:rgba(242, 92, 39, 1)'>正在打印</font>");
        }


        $("#"+check_id).prop("checked",false);
        $("#"+check_id).attr("checked",false);
        $("#"+check_id).attr("disabled", true);
        $.ajax({
            cache: true,
            type:"POST",
            url:basepath+"/spmr/findImg",
            dataType:"json",
            data:{
                onlyId:onlyId,
                combinationContent:combinationContent,
                orgcode:orgcode,
                fs:fs,
                combinationId:combinationId,
                paymentVoucher:	$("#paymentVoucher").val()
            },
            async: true,
            beforeSend: function(xhr){
                xhr.setRequestHeader(header, token);
            },
            success:function(data){

                var num=data.length;
                if(data.length>0){
                    //任务完成总数
                    //printCurrent+=num;

                    $(".alert_warn_new").remove();
                    $("#myModal").append("<div class='alert_warn_new modal' id='dy_alert'><div class='warn_div_dq'><font class='font12' id='warn'>请稍后，正在调取病案...</font></div></div>");

                    $("#dy_alert").append("<div class='alert fade in bar_warn warn_dq' id='bar_close'><div  class='progress progress-striped active'><div class='bar' id='bar_dy' style='width: 1%;'></div></div></div>");
                    //settime_progress($("#dy_alert"),num*0.3);
                    progress_bar_dq(10,2);
                    //progress_bar_dq(2,50/num);

                    for(var i=0;i<fs;i++){
                        if(fs>1){
                            //$("#bar_font").html("正在打印第"+(i+1)+"份，请稍后！");
                        }
                        //打印
                        My_Print(data);
                    }

                    getDyStatefs(num,fs,combinationContent,orgcode,trid,data,fs);

                }else{
                    $("#dy_alert").remove();
                    $("#myModal").append("<div class='alert_warn_new modal' id='dy_alert'><div class='warn_div_dq'><font class='font12' id='warn'>标识码为:"+onlyId+"病案暂未扫描，请咨询人工窗口！</font></div></div>");
                    settime_progress($("#dy_alert"),2);
                    $(".btn_fs").attr("disabled",true);
                    $("#"+trid).attr("style","");
                    var tdid_=trid.split("_")[1]+"_td_"+trid.split("_")[2];
                    $("#"+tdid_).html("<font style='font-size:16px;color:rgba(242, 92, 39, 1)'>暂无法打印</font>");

                    $.ajax({
                        cache: true,
                        type:"POST",
                        url:basepath+"/spmr/getDelay",
                        dataType:"json",
                        data:{delay:5000},
                        async: true,
                        beforeSend: function(xhr){
                            xhr.setRequestHeader(header, token);
                        },
                        success:function(data){
                            getDyStatefs(num,fs,combinationContent,orgcode,"",data,fs);
                        }
                    });

                }



                // setTimeout("close_war()",8000+1000*num*fs);
            },
            error:function(){

                alert("数据错误");
            }
        });
    }else{
        if($("#choiceWarn").length > 0){
            $("#choiceWarn").remove();
        }
        setTimeout(closeWindow(),8000);
    }

}

//查看打印最后任务是否完成
function getDyStatefs(num,fs,combinationContent,orgcode,trid,data,current){
    var basepath=$("#basepath").val();
    printNum=GetStampCount();
    if(printCurrent>255){
    }
    pstate= m607state(GetStatus());
    if(pstate!='true'){
        machineFailure(pstate);
        if(pstate=='卡纸'){
            DelPrinterJob();
            alert("打印机卡纸，未扣费。请到其他自助机再次打印！");
        }else{
            alert("请联系窗口工作人员，打印机"+pstate);
        }
    }
    if(p_id!=''&&p_id!= undefined){

        var flag=true;
        var state=getStatusValue('PRINT_STATUS_EXIST',p_id,'');
        var status=getStatusValue('PRINT_STATUS_ID',p_id,'');
        var sta=getStatusValue('PRINT_STATUS_TEXT',p_id,'');
        //	$("#bjtp").val("1:"+p_id+";"+k+";"+state+";"+status+";"+sta);
        //alert(state+";打印机状态："+status);
        if(printCurrent>(printTime*255+printNum)){
            if(status==8272){
                alert("打印机缺纸，请联系工作人员!");
            }
            if(status==8210){
                alert("打印机故障，请联系工作人员!");
            }
            flag= true;
        }else{
            flag= false;
        }
        if(flag){
            $.ajax({
                cache: true,
                type:"POST",
                url:basepath+"/spmr/getDelay",
                dataType:"json",
                data:{delay:2000},
                async: true,
                beforeSend: function(xhr){
                    xhr.setRequestHeader(header, token);
                },
                success:function(data){
                    getDyStatefs(num,fs,combinationContent,orgcode,trid,data,current);
                }
            });
        }else {
            /*  current=current-1;
              if(current!=0) {
                  var onlyId= $("#onlyId").val();
                  if ($("#choiceWarn").length > 0) {
                      $("#choiceWarn").remove();
                  }
                  $("#myModal").append("<div class='alert fade in ' id='choiceWarn'><div class='warn_div'><font class='font9' id='warn'>标识码为"+onlyId+"，第" + (fs - current) + "份病案，打印完成请取出装订！</font></div></div>");

                  My_Print(data);
                  getDyStatefs(num,fs,combinationContent,orgcode,trid,data,current);
              }else{*/
            if ($("#choiceWarn").length > 0) {
                $("#choiceWarn").remove();
            }
            if (trid != "") {
                //var trid_=trid.split("_")[1]+"_"+trid.split("_")[0]+"_"+trid.split("_")[2];
                var onlyId = $("#" + trid).attr("onlyId");
                //$("#myModal").append("<div class='alert fade in alert_warn_' id='choiceWarn'><div class='warn_div'><font class='font17' id='warn'>标识码为："+onlyId+"的病案，打印完成请装订！</font></div>	<div class='warn_div_'><font class='font5' id='warn_'></font></div></div>");

                $("#" + trid).attr("style", "");
                var tdid_ = trid.split("_")[1] + "_td_" + trid.split("_")[2];
                $("#" + tdid_).html("<font style='font-size:16px;color:rgba(242, 92, 39, 1)'>打印完成</font>");
                //$("#span_"+trid).html("打印完成！");

            }

            choice_print(combinationContent, orgcode);
            $.ajax({
                cache: true,
                type:"POST",
                url:basepath+"/spmr/doPayMdeilcalRecord",
                dataType:"json",
                data:{
                    onlyId			:$("#onlyId").val(),
                    cardno			:$("#outpatient").val(),
                    name			:$("#name").html(),
                    patientIdCardNo	:$("#idcard").html(),
                    num				:num*fs,
                    paymentVoucher	:$("#paymentVoucher").val()
                },
                async: true,
                beforeSend: function(xhr){
                    xhr.setRequestHeader(header, token);
                },
                success:function(data){

                }
            });
            // }
        }

    }else{
        //setTimeout(closeWindow(),8000+1000*num*fs);
    }
}

function My_Print(data){
    //var docPath=$("#docPath").val();
    var num=data.length;
    printCurrent+=num;
    var basepath=$("#basepath").val();
    var docPath="http://11.0.0.55:8081/MrDoc/";

    var date=new Date();
    var month=date.getMonth()+1;
    var strDate=date.getDate();
    var year=date.getFullYear();
    var hour=date.getHours();
    var minute=date.getMinutes();
    var second=date.getSeconds();
    if(month>=1&&month<=9){
        month="0"+month;
    }
    if(strDate>=0&&strDate<=9){
        strDate="0"+strDate;
    }
    if(hour>=0&&hour<10){
        hour="0"+hour;
    }
    if(minute>=0&&minute<10){
        minute="0"+minute;
    }
    if(second>=0&&second<10){
        second="0"+second;
    }
    var currentday=year+"-"+month+"-"+strDate+" "+date.getHours()+":"+minute+":"+second+"     自助打印";

    if(data.length<50){
        LODOP=getLodop();
        LODOP.PRINT_INIT("自助打印");
        LODOP.SET_PRINT_PAGESIZE(1, 0,0,"A4");
        for(var p in data){
            var pagename=data[p].pagename;
            var fileName=data[p].fileName;
            var path;

            if(fileName.indexOf("jpg") >= 0){
                path="<img border='0' src='"+docPath+data[p].organizationId+"/source"+data[p].recordPath+"/"+fileName+"' >";
            }else if(fileName.indexOf(".pdf_page") >= 0){
                fileName=fileName.replace(".pdf_page","");
                path="<img border='0' src='"+docPath+data[p].organizationId+"/thumbnail"+data[p].recordPath+"/"+fileName+".png' >";
            }else{
                fileName=fileName.replace("tif","png");
                path="<img border='0' src='"+docPath+data[p].organizationId+"/thumbnail_"+data[p].recordPath+"/"+fileName+"' >";
            }


            LODOP.ADD_PRINT_IMAGE(0,0,"100%","100%",path);
            LODOP.SET_PRINT_STYLEA(0,"Stretch",2);//按原图比例(不变形)缩放模式
            LODOP.SET_PRINT_STYLE("FontSize",14);
            LODOP.ADD_PRINT_TEXT(23,70,408,30,currentday);
            LODOP.NEWPAGE();
            LODOP.SET_PRINT_MODE("CATCH_PRINT_STATUS",true);
            if(pagename=='病理报告单'){
                LODOP.SET_PRINT_STYLEA(0,"HtmWaitMilSecs",2000);//设置上一项延迟超文本下载2000毫秒
            }else{
                LODOP.SET_PRINT_STYLEA(0,"HtmWaitMilSecs",200);//设置上一项延迟超文本下载200毫秒
            }
        }

        p_id=LODOP.PRINT();
        //alert(p_id);
    }else{
        var num=Math.ceil(data.length/50);
        if(num<1){
            p_id=LODOP.PRINT();
            $("#myModal").append("<div class='alert_warn_banum modal'  onclick='closeBanum()'><div class='warn_div_banum'><font class='font12' id='warn'>该病案不能打印！</font></div></div>");
            settime_banum($(".alert_warn_banum"),5);
        }else{
            for(var i=0;i<num;i++){
                var length=(i+1)*50;
                if(length>data.length){
                    length=data.length;
                }
                LODOP=getLodop();
                LODOP.PRINT_INIT("自助打印");
                LODOP.SET_PRINT_PAGESIZE(1, 0,0,"A4");
                for(var j=i*50;j<length;j++){

                    var fileName=data[j].fileName;
                    var path;
                    if(fileName.indexOf("jpg") >= 0){
                        path="<img border='0' src='"+docPath+data[j].organizationId+"/source"+data[j].recordPath+"/"+fileName+"' >";
                    }else{
                        fileName=fileName.replace("tif","png");
                        path="<img border='0' src='"+docPath+data[j].organizationId+"/thumbnail_"+data[j].recordPath+"/"+fileName+"' >";
                    }
                    LODOP.ADD_PRINT_IMAGE(0,0,"100%","100%",path);
                    LODOP.SET_PRINT_STYLEA(0,"Stretch",2);//按原图比例(不变形)缩放模式
                    LODOP.SET_PRINT_STYLE("FontSize",14);
                    LODOP.ADD_PRINT_TEXT(23,70,408,30,currentday);
                    LODOP.NEWPAGE();
                    LODOP.SET_PRINT_MODE("CATCH_PRINT_STATUS",true);
                }

                //alert(p_id);
                //getDyState(p_id);
                LODOP.SET_PRINT_STYLEA(0,"HtmWaitMilSecs",200);//设置上一项延迟超文本下载1000毫秒
                p_id=LODOP.PRINT();
            }
        }
    }

}

function machineFailure(pstate){
    var failure=$("#failure").val();
    if(!failure||chaMilliseconds(failure)>5){
        $("#failure").val(getMilliseconds());
        var basepath=$("#basepath").val();
        $.ajax({
            cache: true,
            type:"POST",
            url:basepath+"/spmr/saveFailure",
            dataType:"json",
            data:{
                onlyId:$("#onlyId").val(),
                orgcode:$("#orgcode").val(),
                banum:$("#dy_banum").val(),
                name:$("#name").text(),
                fault:pstate
            },
            async: true,
            beforeSend: function(xhr){
                xhr.setRequestHeader(header, token);
            },
            success:function(data1){

            }
        });
    }
}

function getMilliseconds(){
    var myDate = new Date();//获取系统当前时间
    return myDate.getTime(); //获取当前时间(从1970.1.1开始的毫秒数)
}

function chaMilliseconds(milliseconds){
    var reg = /^[\d]+$/;

    if(milliseconds!=null&&reg.test(milliseconds)){
        var current=(getMilliseconds()-milliseconds)/(1000 * 60 );
        return current;
    }

    return 0;
}

function getDyStateNum(num,fs,data,current){
    var basepath=$("#basepath").val();
    printNum=GetStampCount();
    if(printCurrent>255){
        printTime=parseInt(printCurrent/255);
    }
    pstate= m607state(GetStatus());
    if(pstate!='true'){
        machineFailure(pstate);
        if(pstate=='卡纸'){
            DelPrinterJob();
            alert("打印机卡纸，未扣费。请到其他自助机再次打印！");
        }else{
            alert("请联系窗口工作人员，打印机"+pstate);
        }
    }
    //获得打印任务号
    if(p_id!=''&&p_id!= undefined){

        var flag=true;

        var state=getStatusValue('PRINT_STATUS_EXIST',p_id,'');
        var status=getStatusValue('PRINT_STATUS_ID',p_id,'');
        //var sta=getStatusValue('PRINT_STATUS_TEXT',p_id,'');
        //alert(state+";打印机状态："+status);
        if(printCurrent>(printTime*255+printNum)){
            if(status==8272){
                alert("打印机缺纸，请联系工作人员!");
            }
            if(status==8210){
                alert("打印机故障，请联系工作人员!");
            }
            flag= true;
        }else{
            flag= false;
        }
        //检测到未打印完，延时检测
        if(flag){

            $.ajax({
                cache: true,
                type:"POST",
                url:basepath+"/spmr/getDelay",
                dataType:"json",
                data:{delay:2000},
                async: true,
                beforeSend: function(xhr){
                    xhr.setRequestHeader(header, token);
                },
                success:function(data1){
                    getDyStateNum(num,fs,data,current);
                }
            });
        }else{
            //一次打印完成，再打印下一次
            current=current-1;
            if(current!=0){
                if($("#choiceWarn").length > 0){
                    $("#choiceWarn").remove();
                }
                $("#myModal").append("<div class='alert fade in ' id='choiceWarn'><div class='warn_div'><font class='font9' id='warn'>第"+(fs-current)+"份病案，打印完成请取出装订！</font></div></div>");

                //$("#bar_font").html("正在打印第"+(fs-current+1)+"份，请稍后！");
                My_Print(data);
                getDyStateNum(num,fs,data,current);
            }else{
                //扣费
                $.ajax({
                    cache: true,
                    type:"POST",
                    url:basepath+"/spmr/doPayMdeilcalRecord",
                    dataType:"json",
                    data:{
                        onlyId			:$("#onlyId").val(),
                        cardno			:$("#outpatient").val(),
                        name				:$("#name").html(),
                        patientIdCardNo	:$("#idcard").html(),
                        num				:num*fs,
                        paymentVoucher	:$("#paymentVoucher").val()
                    },
                    async: true,
                    beforeSend: function(xhr){
                        xhr.setRequestHeader(header, token);
                    },
                    success:function(data){

                    }
                });
                //单次出院打印完成，关闭窗口
                $.ajax({
                    cache: true,
                    type:"POST",
                    url:basepath+"/spmr/getDelay",
                    dataType:"json",
                    data:{delay:100*num*fs},
                    async: true,
                    beforeSend: function(xhr){
                        xhr.setRequestHeader(header, token);
                    },
                    success:function(data){
                        closeWindow();
                    }
                });
            }

        }

    }else{
        //setTimeout(closeWindow(),8000+1000*num*fs);
    }
}



var k=0;
//查看打印最后任务是否完成
function getDyState(num,fs){
    var basepath=$("#basepath").val();
    k++;
    if(p_id!=''&&p_id!= undefined){

        var flag=true;

        var state=getStatusValue('PRINT_STATUS_EXIST',p_id,'');
        var status=getStatusValue('PRINT_STATUS_ID',p_id,'');
        var sta=getStatusValue('PRINT_STATUS_TEXT',p_id,'');
        $("#bjtp").val("1:"+p_id+";"+k+";"+state+";"+status+";"+sta);
        //alert(state+";打印机状态："+status);
        if(state==1){
            if(status==8272){
                alert("打印机缺纸，请联系工作人员!");
            }
            if(status==8210){
                alert("打印机故障，请联系工作人员!");
            }
            flag= true;
        }else{
            flag= false;
        }
        if(flag){
            $.ajax({
                cache: true,
                type:"POST",
                url:basepath+"/spmr/getDelay",
                dataType:"json",
                data:{delay:2000},
                async: true,
                beforeSend: function(xhr){
                    xhr.setRequestHeader(header, token);
                },
                success:function(data){
                    getDyState(num,fs);
                }
            });
        }else{
            $.ajax({
                cache: true,
                type:"POST",
                url:basepath+"/spmr/getDelay",
                dataType:"json",
                data:{delay:100*num*fs},
                async: true,
                beforeSend: function(xhr){
                    xhr.setRequestHeader(header, token);
                },
                success:function(data){
                    closeWindow();
                }
            });

        }

    }else{
        setTimeout(closeWindow(),8000+1000*num*fs);
    }
}

function closeBanum(){
    settime_banum($(".alert_warn_banum"),0);
}


function closeWindow(){
    StopStamp();
    CloseStamp();
    if($("#choiceWarn").length > 0){
        $("#choiceWarn").remove();
    }
    $("#bar_font").html("打印即将完成，请稍后！");
    $("#bar_close").remove();

    close_war();

}

//查看打印状态
function getStatusValue(ValueType,ValueIndex,oResultOB){
    LODOP=getLodop();
    if (LODOP.CVERSION)
        LODOP.On_Return=function(TaskID,Value){oResultOB.value=Value;};
    var strResult=LODOP.GET_VALUE(ValueType,ValueIndex);
    if (!LODOP.CVERSION)
        return strResult;
    else return "";
};

function payOrder(){
    var basepath=$("#basepath").val();
    var flag=0;
    $.ajax({
        cache: true,
        type:"POST",
        url:basepath+"/spmr/getPayOrder",
        dataType:"json",
        data:{outTradeNo:$("#outTradeCode").val()},
        async: false,
        beforeSend: function(xhr){
            xhr.setRequestHeader(header, token);
        },
        success:function(data){
            if (typeof (data) == "string"){
                var param=data;
                if(param=='null'){

                }else{
                    $("#paymentVoucher").val(data);
                    $("#zfts").remove();
                    $("#qrcode_fs").val("stop");
                    flag=2;
                }

            }

        },
        error:function(){
            alert("失败");
        }
    });
    return flag;
}